package cc.rengu.igas.bsps.common.dao.impl;


import cc.rengu.igas.bsps.common.dao.BspsAgentInfoMapper;
import cc.rengu.igas.bsps.common.entity.AgentInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 代理商信息表操作接口实现类
 * Created by 王成 on 2020/3/10
 */
public class BspsAgentInfoMapperImpl implements BspsAgentInfoMapper {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);

    @Override
    public AgentInfo selectBspsAgentInfoByInstIdAndAgentCode(String instId, String agentCode) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MCMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectBspsAgentInfoByInstIdAndAgentCode");
        AgentInfo agentInfo = new AgentInfo();
        agentInfo.setInstId(instId);
        agentInfo.setAgentCode(agentCode);
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, agentInfo, agentInfo);
        if (0 != iReturnCode) {
            rglog.error("获取代理商信息失败,instId:<{}>,agentCode:<{}>,iReturnCode:<{}>", instId, agentCode, iReturnCode);
            return null;
        }
        return agentInfo;
    }


}
